package com.example.baseproject.main.api;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;

import com.hjq.http.EasyConfig;
import com.hjq.http.annotation.HttpHeader;
import com.hjq.http.annotation.HttpRename;
import com.hjq.http.config.IRequestApi;
import com.hjq.http.config.IRequestBodyStrategy;
import com.hjq.http.config.IRequestCache;
import com.hjq.http.config.IRequestClient;
import com.hjq.http.config.IRequestServer;
import com.hjq.http.config.IRequestType;
import com.hjq.http.model.CacheMode;
import com.hjq.http.model.RequestBodyType;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * @Author jiangKunKun
 * @CreateDate 2022/7/27
 * @Description
 * @SpittingGrooves
 */
@Keep
public class TestApi implements IRequestApi, IRequestServer, IRequestType, IRequestCache, IRequestClient {
    @NonNull
    @NotNull
    @Override
    public String getApi() {
        /**
         * IRequestApi
         * 后半部分接口链接
         * 可拼接 动态变化
         * "login/password/test"
         * "login/password/test?name=" + name
         */
        return "login/password/test";
    }

    @NonNull
    @Override
    public IRequestBodyStrategy getBodyType() {
        return RequestBodyType.JSON;
    }


    /** 用户名 */
    @HttpRename("userName")
    private String userName;
    /** 登录密码 */
    @HttpRename("pwd")
    private String password;
    @HttpHeader()
    private String authType = "COLLECT_DEVICE";
    @HttpHeader()
    private String Language = "zh_CN";
    @HttpHeader()
    private String collectToken = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI3NWJiMzQ4ZC1kNGVhLTQzYjItODM0My01ZjdmMzA4MDgzODciLCJpc3MiOiJTR1JfQ0xPVUQiLCJzdWIiOiJQZXJpcGhlcmFscyIsInVzZXJJZCI6MTg5NzE4MjQzNDM0NTA5NTE3MCwiaWF0IjoxNzQxNDg1MDM5fQ.P9ykZMY3OD_HTbrI4tj1WZY7iGpJnfiCpKbmfwxafYM";

    public TestApi setUserName(String userName) {
        this.userName = userName;
        return this;
    }

    public TestApi setPassword(String password) {
        this.password = password;
        return this;
    }

    @NonNull
    @Override
    public OkHttpClient getOkHttpClient() {
        /**
         * 单独设置某个接口的请求超时时间
         */
        OkHttpClient.Builder builder = EasyConfig.getInstance().getClient().newBuilder();
        builder.readTimeout(5000, TimeUnit.MILLISECONDS);
        builder.writeTimeout(5000, TimeUnit.MILLISECONDS);
        builder.connectTimeout(5000, TimeUnit.MILLISECONDS);
        return builder.build();
    }

    @NonNull
    @Override
    public CacheMode getCacheMode() {
        /**
         * 设置优先使用缓存
         */
        return CacheMode.USE_CACHE_FIRST;
    }


    @NonNull
    @NotNull
    @Override
    public String getHost() {
        /**
         * IRequestServer
         * 多base
         * https://www.baidu.com/
         */

        /**
         * 或者 集成某个第二经常用 XxxServer
         * public final class XxxApi extends XxxServer
         */
        return "https://www.baidu.com/";
    }

//    @HttpHeader
//    @HttpRename("Content-Type")
//    private String contentType = "application/x-www-form-urlencoded;charset=utf-8";


    public static void main(String[] args) {
//        File outputFile;
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//            ContentValues values = new ContentValues();
//            // 生成一个新的 uri 路径
//            Uri outputUri = getContentResolver().insert(MediaStore.Xxx.Media.EXTERNAL_CONTENT_URI, values);
//            // 适配 Android 10 分区存储特性
//            outputFile = new FileContentResolver(context, outputUri);
//        } else {
//            outputFile = new File(xxxx);
//        }

    }
}
